﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<ThreadEntity>>" %>
<%
    var Thanks = ViewData["Thanks"] as List<ThankEntity>;

    var _postLink = ForumContext.GetAbsoluteUrl(ForumUrls.POST);
    string _session = string.Empty;
    string _action = string.Empty;

    if (Model != null)
    {

        int i = 0;

        foreach (var post in Model)
        {
            i++;

            var _thanks = Thanks.Where(x => x.TopicId == post.TopicId);


%>
<div class="fr-widget <%=i > 1 ? "white-space" : string.Empty%> <%=!post.IsApproved?"fr-post-queue":string.Empty %> <%=post.IsDeleted?"fr-post-deleted":string.Empty %>" id="thread_<%=post.TopicId %>">
    <table cellpadding="0" cellspacing="1" width="100%">
        <tr>
            <td colspan="2" class="table-caption" style="font-weight: normal">
                <a class="float-right" name="<%=post.TopicId%>" id="<%=post.TopicId%>" href="<%=ForumContext.FindPost(post.TopicId,post.TopicName)%>">
                    #<%=post.TopicId%></a>
                <%=ForumContext.PrettyDate(post.Created)%>
            </td>
        </tr>
        <tr>
            <td class="table-cell thread-userinfo valign-top" style="padding: 0">
                <div class="thread-username">
                    <a href="<%=ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO,post.UserName) %>">
                        <%=post.UserName%></a></div>
                <%=!string.IsNullOrEmpty(post.Avatar) ? string.Format("<div class=\"user-avatar\"><img src=\"{0}\" style=\"width:{1}px;\" /></div>",post.Avatar,ForumContext.Configuration.AvatarWidth) : string.Empty%>
                <div class="userinfo-extra">
                    <div class="fr-field">
                        <dl>
                            <dt>
                                <%=ForumContext.GetText("UserInfo","GROUP") %>: </dt>
                            <dd class="<%=post.CssClass%>">
                                <%=Html.Encode(post.RoleName)%>
                            </dd>
                        </dl>
                    </div>
                    <div class="fr-field">
                        <dl>
                            <dt>
                                <%=ForumContext.GetText("UserInfo", "RegDate")%>: </dt>
                            <dd>
                                <%=ForumContext.ShortDateTimeFormat(post.RegDate)%>
                            </dd>
                        </dl>
                    </div>
                    <div class="fr-field">
                        <dl>
                            <dt>
                                <%=ForumContext.GetText("UserInfo", "TotalPosts")%>: </dt>
                            <dd>
                                <%=post.TotalPosts%>
                            </dd>
                        </dl>
                    </div>
                    <div class="fr-field">
                        <dl>
                            <dt>
                                <%=ForumContext.GetText("UserInfo", "TotalVisits")%>: </dt>
                            <dd>
                                <%=post.TotalVisits%>
                            </dd>
                        </dl>
                    </div>
                </div>
            </td>
            <td class="table-cell valign-top" style="padding: 0">
                <div class="thread-title">
                    <%
                        if (!string.IsNullOrEmpty(post.Icon))
                        {%>
                    <img src="<%=ForumContext.Configuration.TopicSmiles + post.Icon%>" alt="<%=post.Icon%>"
                        class="smile" />
                    <%
                        }%>
                    <h1>
                        <%=Html.Encode(post.TopicName)%></h1>
                </div>
                <div class="thread-message">
                    <%=post.Message.BbCodeToHtml().HighlightKeywords()%>
                </div>
                <%
                    if (!string.IsNullOrEmpty(post.Signature))
                    {%>
                <div class="user-signature">
                    <%=post.Signature%>
                </div>
                <%
                    }%>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="table-cell">
                <div class="button-command-panel">
                    <% if (ForumContext.Logined && post.UserId != ForumContext.UserInfo.UserId && _thanks != null && !_thanks.Any(x => x.UserId == ForumContext.UserInfo.UserId))
                       {
                          
                    %>
                    <button class="button-icon-min" onclick="$.MvcForum.thank('<%=ForumContext.GetAbsoluteUrl(ForumUrls.THANK)%>?Id=<%=post.TopicId %>','#thread_<%=post.TopicId %>');">
                        <span class="icon-b icon-thank">&nbsp;</span> <span class="button-text">
                            <%=ForumContext.GetText("Topics", "Thank")%></span>
                    </button>
                    <%
}

                       _session = ForumContext.Encrypt((int)CommandType.Reply, post.TopicId);

                       _action = string.Format("window.location='{0}?sessionId={1}'", _postLink, _session);
                          
            
                    %>
                    <button class="button-icon-min" onclick="<%=_action %>">
                        <span class="icon-b icon-reply">&nbsp;</span> <span class="button-text">
                            <%=ForumContext.GetText("Topics","Reply") %></span>
                    </button>
                    <% _session = ForumContext.Encrypt((int)CommandType.Quote, post.TopicId);

                       _action = string.Format("window.location='{0}?sessionId={1}'", _postLink, _session);
                    %>
                    <button class="button-icon-min" onclick="<%=_action %>">
                        <span class="icon-b icon-quote">&nbsp;</span> <span class="button-text">
                            <%=ForumContext.GetText("Topics","Quote") %></span>
                    </button>
                    <% if (ForumContext.Logined && (post.UserId == ForumContext.UserInfo.UserId || ForumContext.UserInfo.IsAdmin))
                       {


                           _session = ForumContext.Encrypt((int)CommandType.Edit, post.TopicId);

                           _action = string.Format("window.location='{0}?sessionId={1}'", _postLink, _session);

                           //_action = string.Format("{0}?ajax=true&sessionId={1}", _postLink, _session);
                           //$.Window.show({ title: 'ForumContext.GetText("THREAD","QUICK_EDIT") ', url: '_action ', width: 800, height: 500 });
                       

                    %>
                    <button class="button-icon-min" onclick="<%=_action %>">
                        <span class="icon-b icon-edit">&nbsp;</span> <span class="button-text">
                            <%=ForumContext.GetText("Topics","Edit") %></span>
                    </button>
                    <%
                        }%>
                    <% if (ForumContext.Logined && (ForumContext.UserInfo.IsAdmin))
                       {

                           _session = ForumContext.Encrypt((int)CommandType.Delete, post.TopicId);
                          
                    %>
                    <button class="button-icon-min" onclick="if (confirm('<%=ForumContext.GetText("THREAD","CONFIRM_DEL") %>')) { $.MvcForum.cmd('<%=_session %>','$.MvcForum.deleteSuccess(msg)')}">
                        <span class="icon-b icon-del">&nbsp;</span> <span class="button-text">
                            <%=ForumContext.GetText("Topics","Del") %></span>
                    </button>
                    <%
                        }%>
                </div>
               
               <%if(ForumContext.Logined && (ForumContext.UserInfo.IsAdmin || ForumContext.UserInfo.IsModerated(post.ForumId)))
{
    Response.Write("<input type=\"checkbox\" class=\"item-selected\" value=\""+post.TopicId+"\" />");
}
                      %>
            </td>
        </tr>
        <%


            if (_thanks.Count() > 0)
            {


        %>
        <tr>
            <td class="table-cell" colspan="2">
                <%=String.Format(ForumContext.GetText("Topics", "SAID_THANKS"), post.UserName)%>
                <div id="thank_panel_<%=post.TopicId%>">
                    <%

                        int _iCount = 0;
                        foreach (var _thank in _thanks)
                        {
                            if (_iCount > 0)
                                Response.Write(",");
                            Response.Write(string.Format(" <a href=\"{0}\" title=\"{1}\">{1}</a> ({2})",
                                                         ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO,
                                                                                     _thank.UserName),
                                                         _thank.UserName, ForumContext.PrettyDate(_thank.Created)));
                            _iCount++;

                        }%>
                </div>
            </td>
        </tr>
        <%
            }%>
    </table>
</div>
<%
            
}
    } %>
